<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户沟通记录</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>

<body class="iframeBody">
    <div class="Wrapper">
        <div class="sqPanel">
            <div class="sqPanel_head inL">
                <div class="btnsBox inLC">
                    <span id="cst_comm_rec_add_btn_id" class="sq-button sq-button-round">添加</span>
                    <span id="cst_comm_rec_modify_btn_id" class="sq-button sq-button-round">修改</span>
                    <!-- <span id="cst_comm_rec_detail_btn_id" class="sq-button sq-button-round">详情</span> -->
                </div>
                <span>沟通记录</span>
            </div>
            <div class="sqPanel_body">
                <div id="cst_comm_rec_grid_id" class="sq-grid"></div>
            </div>
        </div>
    </div>
 	<!-- hide data -->
	<div class="fieldBox col_100" style="display:none;">
		<div class="field">
		    <input name=cstId id="cstId" type="text" class="ui-textbox" value="${cstId}">
		</div>
	</div>
    

    <script>
    $(function() {
    	var _cstId = $("#cstId").val();
    	//新增
        $("#cst_comm_rec_add_btn_id").click(function(event) {
            //如果客户ID不存在是不能新增的
        	if(!_cstId){
        		$.ligerDialog.SQalert({content:LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO, SQ_type: "warning"});
                return; //验证不通过，不执行以下代码
        	}
            $.ligerDialog.open({
                cls: 'noBorder_Dialog',
                width: 800,
                height:380,
                title : '新增',
                url:'<%=path%>/customer/cstcommrec/toAddPage.do?cstId='+_cstId,
                // 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                        text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onOk = function () {}
                            if (Dialog.onOk) Dialog.onOk();
                        }
                    }, {
                        text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                            if (Dialog.onCancel) Dialog.onCancel();
                        }
                    }
                ]
            });
        });
        
        //修改
        $("#cst_comm_rec_modify_btn_id").click(function(event) {
        	//如果客户ID不存在是不能修改
        	var _cstId = $("#cstId").val();
        	if(!_cstId){
        		$.ligerDialog.SQalert({content:LogUtils.LOG_CUST_CONFIRM_HERE_HAS_INFO, SQ_type: "warning"});
                return; //验证不通过，不执行以下代码
        	}
        	
        	var selectedRows = grid.getSelectedRows();
    		if(selectedRows.length != 1){
    			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warning"});
    			return;
    		}
    		
    		var _id = selectedRows[0].id;
    		
    		var isOper = selectedRows[0].isOper;
        	if(isOper == 0){
        		$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MODIFY_AUTH_NO, SQ_type: "warning"});
        		return;
        	}
    		
            $.ligerDialog.open({
                cls: 'noBorder_Dialog',
                width: 800,
                height:380,
                title : '修改',
                url:'<%=path%>/customer/cstcommrec/toAddPage.do?cstId='+_cstId+'&id='+_id,
             	// 自定义buttons的时候 不要设置 fixButtons: true
                buttons: [{
                        text: "保存", type: 'ok', cls: 'l-dialog-btn-ok', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onOk = function () {}
                            if (Dialog.onOk) Dialog.onOk();
                        }
                    }, {
                        text: "取消", type: 'cancel', cls: 'l-dialog-btn-no', 
                        onclick: function (item, Dialog) {
                            //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                            if (Dialog.onCancel) Dialog.onCancel();
                        }
                    }
                ]
            });
        });
        
        
		//初始化Grid
        $("#cst_comm_rec_grid_id").ligerGrid({
            usePager: false,
            url: "<%=path%>/customer/cstcommrec/initList.do?cstId="+_cstId,
            method : 'get',
            columns: [{
                display: '沟通时间',
                name: 'commDt',
                width: 150,
                render:renderDate
            }, {
                display: '沟通方式',
                name: 'commWayCdNm',
                width: 150
            }, {
                display: '责任人',
                name: 'respPsn',
                minWidth: 150,
                render: function (rowdata, rowindex, value, column) { 
            		var h = '';
        		    h='<a  href="javascript:cstCommRecDetail(';
                    h+="'"+rowdata.id+"'";
                    h+=')">'+value+'</a>'
                    return h;
        		}
            }, {
                display: '联系人',
                name: 'linkman',
                minWidth: 150
            }, {
                display: '联系电话',
                name: 'contactNum',
                minWidth: 150
            }, {
                display: '简要记录',
                name: 'briefRec',
                minWidth: 200
            }, {
                display: '反馈记录',
                name: 'feedbackRec',
                minWidth: 200
            }, {
                display: '成因说明',
                name: 'rsnDesc',
                minWidth: 200
            }, getGridOperColumnContent()],
            width: '100%',
            //isScroll: false,
            height:'100%',
			heightDiff:-2,
            root:'rows',
	        record:'total',
            rownumbers: true,
            fixedCellHeight: false,
            usePagerOnLessPagesize: false,
            onAfterShowData: function(currentData) {
                SetIframe_height();
                $(".liger_tip").ligerTip();
            }
        });
        grid = liger.get("cst_comm_rec_grid_id");
        grid.setHeight(500);
    });
    
  	//详情
    function cstCommRecDetail(_id){
    	$.ligerDialog.open({
            cls: 'noBorder_Dialog',
            width: 800,
            height:380,
            title : '详情',
            url:'<%=path%>/customer/cstcommrec/toDetailPage.do?id='+_id,
         	// 自定义buttons的时候 不要设置 fixButtons: true
            buttons: [{
                    text: "关闭", type: 'cancel', cls: 'l-dialog-btn-no', 
                    onclick: function (item, Dialog) {
                        //在子页面里绑定 frameElement.dialog.onCancel = function () {}
                        if (Dialog.onCancel) Dialog.onCancel();
                    }
                }
            ]
        });
    }
    
  	//Grid操作列
    function getGridOperColumnContent(){
    	var data = {
                display: '操作',
                isSort: false,
                width: 70,
                render: function (rowdata, rowindex, value){
                	if(rowdata.isOper == 0) return "";
                    var h='<a class="sq-button-hasicon" href="javascript:deleteRow(';
                        h+="'"+rowdata.id+"'";
                        h+=",'cst_comm_rec_grid_id'"
                        h+=")\"><i class=\"sqBtnIco_7\"></i>"+LogUtils.LOG_CMM_GRID_BTN_DELETE+"</a>"
                    return h;
                }
            }
    	return data;
	}
    
    //删除信息
    function deleteRow(_id, gridId) {
    	var cstId = $("#cstId").val();
    	if(!cstId){
    		$.ligerDialog.SQalert({content: LogUtils.LOG_CUST_ID_NOT_EMPTY, SQ_type: "warning"});
    		return;
    	}
    	$.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
			if(flag == false)return;
			 var wait_dialog= $.ligerDialog.SQalert({
		            content: LogUtils.LOG_CMM_LOADING,
		            SQ_type: "waitting",
		            onClose: function () {
		            }
		        });
			$.ajax({
	     		type: 'post',
	     		dataType:'json',
	     		data:{id:_id},
	     		url: '<%=path%>/customer/cstcommrec/removeById.do',
	     		success:function(msg){
	     			wait_dialog.close();
	     			 if(msg.success == 1){
	     				$.ligerDialog.SQalert({content: msg.info,SQ_type: "success"});
	     				grid.setParm("cstId",cstId);
	     				grid.reload();
	     			 }else{
	     				$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
	     			 }
	     		}
	     	});
		});
    }
    
    //格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}
    </script>
</body>

</html>
